﻿using System;
using System.Collections;
using System.Data;
using System.IO;

public partial class Admin_News_QL_Anh : System.Web.UI.Page
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        FillData();
    }

    private void FillData()
    {
        DataTable table = data.GetTable_By_Name("AnhChay");

        imgHientai1.ImageUrl = "../../Images/AnhChay/" + table.Rows[0]["AnhChayImage"].ToString();
        imgHientai2.ImageUrl = "../../Images/AnhChay/" + table.Rows[1]["AnhChayImage"].ToString();
        imgHientai3.ImageUrl = "../../Images/AnhChay/" + table.Rows[2]["AnhChayImage"].ToString();
        imgHientai4.ImageUrl = "../../Images/AnhChay/" + table.Rows[3]["AnhChayImage"].ToString();
        imgHientai5.ImageUrl = "../../Images/AnhChay/" + table.Rows[4]["AnhChayImage"].ToString();

        txtlinkbandau1.Text = table.Rows[0]["AnhChayLink"].ToString();
        txtlinkbandau2.Text = table.Rows[1]["AnhChayLink"].ToString();
        txtlinkbandau3.Text = table.Rows[2]["AnhChayLink"].ToString();
        txtlinkbandau4.Text = table.Rows[3]["AnhChayLink"].ToString();
        txtlinkbandau5.Text = table.Rows[4]["AnhChayLink"].ToString();
    }
    protected void btnUploadThu1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/AnhChay/" + FileUpload1.FileName));
            imgFuture1.ImageUrl = "../../images/AnhChay/" + FileUpload1.FileName;
            Session["AnhChay1"] = FileUpload1.FileName;
        }
    }
    protected void btnSaveLink1_Click(object sender, EventArgs e)
    {
        if (txtlinkmoi.Text.Trim().Length != 0)
        {
            data.Edit_LinkAnhChay(txtlinkmoi.Text,"3");
            Exit();
        }
        else
        {
            lblLinkThaythe1.Text = "Không thể thay link";
        }
    }
    protected void btnSave1_Click(object sender, EventArgs e)
    {
        if (imgFuture1.ImageUrl.Equals("") == false && Session["AnhChay1"] != null)
        {
            data.Edit_LinkAnhurl(Session["AnhChay1"].ToString(),"3");
            Exit();
        }
    }
    protected void btnCancel1_Click(object sender, EventArgs e)
    {
        Exit();
    }
    protected void btnUploadThu2_Click(object sender, EventArgs e)
    {
        if (FileUpload2.HasFile)
        {
            FileUpload2.SaveAs(Server.MapPath("~/images/AnhChay/" + FileUpload2.FileName));
            imgFuture2.ImageUrl = "../../images/AnhChay/" + FileUpload2.FileName;
            Session["AnhChay2"] = FileUpload2.FileName;
        }
    }
    protected void btnSaveLink2_Click(object sender, EventArgs e)
    {
        if (txtlinkmoi2.Text.Trim().Length != 0)
        {
            data.Edit_LinkAnhChay(txtlinkmoi2.Text, "6");
            Exit();
        }
        else
        {
            lblLinkThaythe2.Text = "Không thể thay link";
        }
    }
    protected void BtnSave2_Click(object sender, EventArgs e)
    {
        if (imgFuture2.ImageUrl.Equals("") == false && Session["AnhChay2"] != null)
        {
            data.Edit_LinkAnhurl(Session["AnhChay2"].ToString(), "6");
            Exit();
        }
    }
    protected void btnCancel2_Click(object sender, EventArgs e)
    {
        Exit();
    }
    protected void btnUploadThu3_Click(object sender, EventArgs e)
    {
        if (FileUpload3.HasFile)
        {
            FileUpload3.SaveAs(Server.MapPath("~/images/AnhChay/" + FileUpload3.FileName));
            imgFuture3.ImageUrl = "../../images/AnhChay/" + FileUpload3.FileName;
            Session["AnhChay3"] = FileUpload3.FileName;
        }
    }
    protected void btnSave3_Click(object sender, EventArgs e)
    {
        if (imgFuture3.ImageUrl.Equals("") == false && Session["AnhChay3"] != null)
        {
            data.Edit_LinkAnhurl(Session["AnhChay3"].ToString(), "9");
            Exit();
        }
    }
    protected void btnSaveLink3_Click(object sender, EventArgs e)
    {
        if (txtlinkbandau3.Text.Trim().Length != 0)
        {
            data.Edit_LinkAnhChay(txtlinkmoi3.Text, "9");
            Exit();
        }
        else
        {
            lblLinkThaythe3.Text = "Không thể thay link";
        }
    }
    protected void btnCancel3_Click(object sender, EventArgs e)
    {
        Exit();
    }
    protected void btnUploadThu4_Click(object sender, EventArgs e)
    {
        if (FileUpload4.HasFile)
        {
            FileUpload4.SaveAs(Server.MapPath("~/images/AnhChay/" + FileUpload4.FileName));
            imgFuture4.ImageUrl = "../../images/AnhChay/" + FileUpload4.FileName;
            Session["AnhChay4"] = FileUpload4.FileName;
        }
    }
    protected void btnSaveLink4_Click(object sender, EventArgs e)
    {
        if (txtlinkmoi4.Text.Trim().Length != 0)
        {
            data.Edit_LinkAnhChay(txtlinkbandau4.Text, "10");
            Exit();
        }
        else
        {
            lblLinkThaythe4.Text = "Không thể thay link";
        }
    }
    protected void btnSave4_Click(object sender, EventArgs e)
    {
        if (imgFuture4.ImageUrl.Equals("") == false && Session["AnhChay4"] != null)
        {
            data.Edit_LinkAnhurl(Session["AnhChay4"].ToString(), "10");
            Exit();
        }
    }
    protected void btncancel4_Click(object sender, EventArgs e)
    {
        Exit();
    }
    protected void btnUploadThu5_Click(object sender, EventArgs e)
    {
        if (FileUpload5.HasFile)
        {
            FileUpload5.SaveAs(Server.MapPath("~/images/AnhChay/" + FileUpload5.FileName));
            imgFuture5.ImageUrl = "../../images/AnhChay/" + FileUpload5.FileName;
            Session["AnhChay5"] = FileUpload5.FileName;
        }
    }
    protected void btnSaveLink5_Click(object sender, EventArgs e)
    {
        if (txtlinkmoi5.Text.Trim().Length != 0)
        {
            data.Edit_LinkAnhChay(txtlinkmoi5.Text, "12");
            Exit();
        }
        else
        {
            lblLinkThaythe5.Text = "Không thể thay link";
        }
    }
    protected void btnSave5_Click(object sender, EventArgs e)
    {
        if (imgFuture5.ImageUrl.Equals("") == false && Session["AnhChay5"] != null)
        {
            data.Edit_LinkAnhurl(Session["AnhChay5"].ToString(), "12");
            Exit();
        }
    }
    protected void btnCancel5_Click(object sender, EventArgs e)
    {
        Exit();
    }
    private void Exit()
    {
        Session["AnhChay1"] = null;
        Session["AnhChay2"] = null;
        Session["AnhChay3"] = null;
        Session["AnhChay4"] = null;
        Session["AnhChay5"] = null;
        Response.Redirect("Default.aspx");
    }
}
